import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;


// An Image Extractor 
// Takes an URL, a file location where the images are stored, and a number of images extracted. 

public class ImageExtractorURL {
	static int index= 423; //the number of images extracting from a URL
	static String theURL = "http://www.angelfire.com/games5/unholy1/sprites/umk3/scorp/"; //the URL
	static String theFile = "Images/MK Scorpion/image"; //the file where the images will be stored
	
	public static void main(String[] args) throws IOException{
		for(int i = 1; i < 423; i++)
			extract(i);
		System.out.println("Done!");
	}
	
	public static void extract(int index) throws IOException{
		URL url = new URL(theURL + index + ".png");
		URLConnection urlConnection = url.openConnection();

		// creating the input stream from google image
		BufferedInputStream in = new BufferedInputStream(urlConnection.getInputStream());
		// my local file writer, output stream
		BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream( theFile + index + ".png" ));

		// until the end of data, keep saving into file.
		int i;
		while ((i = in.read()) != -1) {
		    out.write(i);
		}
		out.flush();

		out.close();
		in.close();
	}
	

}
